package com.zctest.service.impl;

import com.zctest.CommonException;
import com.zctest.entity.Book;
import com.zctest.entity.Company;
import com.zctest.entity.User;
import com.zctest.service.BookService;
import com.zctest.service.CommonService;
import com.zctest.service.CompanyService;
import com.zctest.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zhangchao
 * @version 1.0
 * @date 2019/1/7
 */
@Service
public class CommomServiceImpl implements CommonService {
    @Autowired
    private UserService userService;
    @Autowired
    private BookService bookService;
    @Autowired
    private CompanyService companyService;

    @Transactional
    @Override
    public void save() {
        try {
            userService.save(new User());
            bookService.save(new Book());
            companyService.save(new Company());
        } catch (CommonException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void saveNotTransaction() {
        try {
            userService.saveTogether(new User());
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.err.println("1111");
    }
}
